<?php
/**
 * Created by PhpStorm.
 * User: L
 * Date: 2018/11/23
 * Time: 15:01
 * Updata Time:2018/11/26  12:54
 */

namespace app\models\Project_1_0;


use Core\Model;

class Wxdecode extends Model

{    

    function search(){
      $appid = 'wx1595b492608a8157';
        $sessionKey = $_REQUEST['session_key'];
        $encryptedData=$_REQUEST['encryptedData'];
        $iv = $_REQUEST['iv'];
        $pc = new \WXBizDataCrypt($appid,$sessionKey);
        $errocode=$pc->decryptData($encryptedData,$iv,$data); 
        print($data."\n");//打印 解析内容
        if($errocode==0) {
            //查询用户信息
            $arr=json_decode($data,true);//把解析的数据转为数组
            // print_r(array_values($arr));//打印测试数组
            $phone=$arr['phoneNumber'];//获取值
            //var_dump($phone);//打印测试值
            $sql = "select * from t_user where tel='{$phone}'";
            $res = $this->db->getRow($sql);
            if ($res != null) {
            echo "该用户已存在";
                //return $res;
            } else {
                echo "该用户不存在";
                $sql1="insert into t_user (tel) value ('{$phone}')";//插入用户数据
                $res=$this->db->fetch_sql($sql1);
        if($res!=null){

            echo "插入失败";
            return $res;
        }
        else{
            echo"插入成功";
        }

            }
  }
    
        else{
        //    print($sessionKey."\n");
         //   print($encryptedData."\n");
          //  print($iv."\n");
            print($errocode."\n");
            //打印测试sesionkey,加密内容， iv等
        }

        }
}